package com.vagavaga.tx;

import java.sql.Connection;

/**
 * Transaction abstraction.
 *
 * @author <code>river</code>
 * @version $Revision: 1.4 $ $Date: 2004/05/31 21:14:42 $
 */
class Transaction {
    /**
     * Is this transaction marked to be rolled back.
     */
    private boolean rollbackOnly;

    /**
     * Original connection that this transaction is wrapping.
     */
    private final Connection connection;

    /**
     * Creates transaction that wraps <code>conn</code>.
     * @param conn Connection to wrap in transaction.
     */
    public Transaction(Connection conn) {
        connection = conn;
    }

    /**
     * Returns wrapped connection. Note that this connection is raw connection
     * returned from datasource. It has no interceptors.
     * @return connection that this transaction wraps.
     */
    public Connection getConnection() {
        return connection;
    }

    /**
     * Marks this transaction as rollbac only. Transaction can not commit, but
     * will eventualy rollback.
     */
    public void setRollbackOnly() {
        rollbackOnly = true;
    }

    /**
     * Test is this transaction marked as rollback only.
     * @return true if transaction is marked for rollback.
     */
    public boolean isRollbackOnly() {
        return rollbackOnly;
    }

}
